#!/usr/bin/env python

#!/usr/bin/env python
from lib.format_time import *
from lib.HandleMysql import *
from lib.switch_code import *
from shop_conn import *
import sys
import re
reload(sys)
sys.setdefaultencoding('utf-8')

def get_product_data():
    prod_conn = set_product_conn()
    stat_conn = set_stats_conn()
    stat_table = "test"
     
    query = "select productid,title,cateid,shopid,minPrice,local from t_product where cateid in (207,310,311)  and state=1"
    items = prod_conn.get_results(query)
    for item in items:
        prod_id = item[0]
        title = item[1]
        cate_id = item[2]
        shop_id = item[3]
        price = item[4]
        local = item[5]
        
        p_cityid = 0
        if local != None:            
            pattern =  re.compile(r'"L":(\w*)')
            matchs = pattern.search(local)
            try:
                p_cityid = matchs.group(1)
            except Exception,e:
                p_cityid = 0
                
        param = [prod_id,title,shop_id,'',price,0,'',cate_id,'',0,p_cityid]
        stat_conn.insert_record(stat_table,param)
        
        

if __name__=='__main__':
    get_product_data( ) 